home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / Headers / gamekit / GKCollider.h < prev    next >
Text File  |  1995-06-12  |  2KB  |  50 lines

  1.  
  2. #import <gamekit/gamekit.h>
  3.  
  4. // These are the shape tags used to tell the collision machinery what
  5. // methods to call in order to verify a collision between two objects.
  6. // You can add your own types, but you MUST use prime numbers for the
  7. // new tags!  (Note that the hash table must be loaded with a proper
  8. // collision method for each combo...for example the collision method
  9. // for a triangle and rectangle has a hash tag of GK_RECTANGLE_SHAPE
  10. // multiplied by GK_TRIANGLE_SHAPE == 10, so the hash table's slot #10
  11. // has the info on how to intersect a rectangle and triangle.)
  12. #define GK_RECTANGLE_SHAPE    2
  13. #define GK_CIRCLE_SHAPE        3
  14. #define GK_TRIANGLE_SHAPE    5
  15. #define GK_COMPOSITE_SHAPE    7
  16.  
  17. BOOL GKPointAboveLine(NXPoint *point, NXPoint *start, NXPoint *end);
  18. BOOL GKPointsOnSameSideOfLine(NXPoint *point1, NXPoint *point2, NXPoint *start, NXPoint *end);
  19. extern double GKDistanceBetweenPoints(NXPoint *point1, NXPoint *point2);
  20. extern double GKSegmentAngle(NXPoint *point1, NXPoint *point2);
  21. extern BOOL GKOuterLineSegmentIntersectsRect(NXPoint *point1, NXPoint *point2, NXRect *rect);
  22. extern BOOL GKPointInTriangle(NXPoint *point, GKTriangle *tri);
  23.  
  24. @interface GKCollider:Object
  25. {
  26.     id collisionHash;    // a HashTable used to hold collision methods
  27. }
  28.  
  29. + new;    // returns the global GKCollider -- NEVER use alloc/init!!!
  30. - buildHashTable;    // does set up, called by new as needed;
  31.     // override to add new shapes and then add detection methods as below...
  32.  
  33. // This is the only method an external object needs to call
  34. - (BOOL)object:actor1 collidesWith:actor2;
  35.  
  36. // built-in collision detection methods
  37. // Note that the arg with the lower tag MUST come first!!!
  38. - (int)rect:(NXRect *)rect1 intersectsRect:(NXRect *)rect2;
  39. - (int)rect:(NXRect *)rect intersectsCircle:(GKCircle *)circ;
  40. - (int)rect:(NXRect *)rect intersectsTriangle:(GKTriangle *)tri;
  41. - (int)rect:(NXRect *)rect intersectsComposite:comp;
  42. - (int)circle:(GKCircle *)circ1 intersectsCircle:(GKCircle *)circ2;
  43. - (int)circle:(GKCircle *)circ intersectsTriangle:(GKTriangle *)tri;
  44. - (int)circle:(GKCircle *)circ intersectsComposite:comp;
  45. - (int)triangle:(GKTriangle *)tri1 intersectsTriangle:(GKTriangle *)tri2;
  46. - (int)triangle:(GKTriangle *)tri intersectsComposite:comp;
  47. - (int)composite:(GKTriangle *)comp1 intersectsComposite:comp2;
  48.  
  49. @end
  50.